#include <iostream>
#include <string>
#include <vector>
using namespace std;

struct node {
    node* left;
    node* right;
    char data;
};

node* create_node();
void post_traverse(node* tree);
node* insert_node(node* tree, char data);

int main(int argc, char const* argv[])
{
    char input[50];
    vector<string> data;
    while (scanf("%s", input) != EOF) {
        if (input[0] == '$' || input[0] == '*') {
            node* tree = nullptr;
            for (int i = data.size() - 1; i >= 0; i--) {
                string node_set = data[i];
                for (int j = 0; j < node_set.size(); j++) {
                    tree = insert_node(tree, node_set[j]);
                }
            }
            post_traverse(tree);
            printf("\n");

            if (input[0] == '$')
                break;
            if (input[0] == '*') {
                data.clear();
                continue;
            }
        } else {
            string str = input;
            data.push_back(str);
        }
    }
    return 0;
}

node* create_node()
{
    node* return_node = new node;
    return_node->left = nullptr;
    return_node->right = nullptr;
    return return_node;
}

void post_traverse(node* tree)
{
    printf("%c", tree->data);
    if (tree->left) {
        post_traverse(tree->left);
    }
    if (tree->right) {
        post_traverse(tree->right);
    }
}

node* insert_node(node* tree, char data)
{
    if (!tree) {
        node* return_node = create_node();
        return_node->data = data;
        return return_node;
    } else if ((int)data < (int)tree->data) {
        tree->left = insert_node(tree->left, data);
    } else {
        tree->right = insert_node(tree->right, data);
    }
    return tree;
}